<?php
/**
 * main controller
 * @uses Magnum_View
 * @uses Magnum_Handler_Post
 * @uses Magnum_Handler_Get
 */
class Magnum_Control
{
    /**
     * view object
     * @var Magnum_View
     */
    protected $_view = null;


    /**
     * request
     * @var array
     */
    protected $_req = array();


    // constructor
    public function __construct($view, $gethandler = 'Magnum_Handlers_Get', $postHandler = 'Magnum_Handlers_Post')
    {
        $this->_view = new $view;

        // handle the event
        $this->_handleEvent($gethandler, $postHandler);

    }// end __construct


    /**
     * handle event
     * for handler to handle
     * @return self;
     */
    protected function _handleEvent($gethandler, $postHandler)
    {
        // get the params...
        $reqs = parse_url(str_replace(Magnum::dir('BASEURL'), '', $_SERVER['REQUEST_URI']));
        if (empty($reqs['path'])) {
            $reqs['path'] = 'index';
        }

        $this->_req = (array) explode('/', $reqs['path']);

        // clear .html/.htm off the req
        $cnt = count($this->_req) - 1;
        $this->_req[$cnt] = str_replace(array('.html', '.htm'), '', $this->_req[$cnt]);

        // handle get...
        new $gethandler($this);

        // handle it...
        // after get, handle the post..
        if (!empty($_POST)) {
            // only when there's post
            new $postHandler($this);
        }

        return $this;

    }// end _getEvent


    /**
     * get request
     * @return str
     */
    public function getRequest()
    {
        return $this->_req;

    }// end getRequest


    /**
     * get view
     * @return Magnum_View
     */
    public function getView()
    {
        return $this->_view;

    }// end getView

}// end Magnum
?>